﻿using System;
using System.Collections.Generic;

public class XMLParserInfo
{
    public Type m_type;
    public string m_path;
    public XMLParserBase m_parser;
    public XMLParserInfo(Type t, string sp, XMLParserBase xb)
    {
        m_type = t;
        m_path = sp;
        m_parser = xb;
    }
}

public class XmlFileInfo
{
    public string path = "";
    public bool isFolder = false;
    public override bool Equals(object obj)
    {
        if (obj == null)
        {
            return false;
        }
        XmlFileInfo info = obj as XmlFileInfo;
        if (info == null)
        {
            return false;
        }
        if (info.isFolder == this.isFolder)
        {
            return this.path.Equals(info.path);
        }
        else if (info.isFolder)
        {
            return this.path.Contains(info.path);
        }
        else
        {
            return info.path.Contains(this.path);
        }
    }

    public XmlFileInfo(string _path, bool _isFolder)
    {
        path = _path;
        isFolder = _isFolder;
    }

    //重写GetHashCode方法（重写Equals方法必须重写GetHashCode方法，否则发生警
    public override int GetHashCode()
    {
        return this.path.GetHashCode() + isFolder.GetHashCode();
    }
}

public class XMLObjectRegister
{
    static Dictionary<string, Type> m_type_info_dict = new Dictionary<string, Type>();
    static HashSet<string> m_file_set = new HashSet<string>();
    static HashSet<string> m_folder_set = new HashSet<string>();
    static bool m_binit = false;

    public static void RegistAllObject()
    {
        if (m_binit == true)
        {
            return;
        }
        RegisterXMLObject(typeof(DressListInfo), XmlPathDefines.Dress);
        m_binit = true;
    }
    public static void RegisterXMLObject(Type t, string xmlpath)
    {
        if (!m_file_set.Contains(xmlpath))
        {
            m_file_set.Add(xmlpath);
        }
        if (m_type_info_dict.ContainsKey(t.Name) == false)
        {
            m_type_info_dict.Add(t.Name, t);
        }
    }

    public static void RegisterXMLObjectParser(Type t, string xmlpath)
    {
        if (!m_file_set.Contains(xmlpath))
        {
            m_file_set.Add(xmlpath);
        }
    }

    public static Type FindXMLObject(string typename)
    {
        if (m_type_info_dict.ContainsKey(typename) == false)
        {
            return null;
        }
        else
        {
            return m_type_info_dict[typename];
        }
    }

    public static HashSet<string> GenTransFileList()
    {
        return m_file_set;
    }
    public static bool ContainsInFolderList(string key)
    {
        foreach (string folder in m_folder_set)
        {
            if (key.Contains(folder))
            {
                return true;
            }
        }
        return false;
    }

    public static bool ContainsInFileList(string key)
    {
        foreach (string file in m_file_set)
        {
            if (key.Contains(file))
            {
                return true;
            }
        }
        return false;
    }
}
